package com.dragon.repository.domain.vo;

import com.baomidou.mybatisplus.annotation.TableField;
import com.dragon.common.model.Update;
import com.dragon.common.util.BeanUtils;
import com.dragon.repository.entity.Admin;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


/**
 * @author sy
 */
@Data
@ApiModel(value = "")
public class AdminVO {

    private static final long serialVersionUID = 1L;

    private Integer id;

    @ApiModelProperty(value = "用户名")
    private String username;

    @ApiModelProperty(value = "密码")
    private String password;

    @ApiModelProperty(value = "头像")
    private String img;

    @ApiModelProperty(value = "账号")
    private String account;

    @ApiModelProperty(value = "账号状态：1启用2禁用")
    private Integer state;

    @ApiModelProperty(value = "账号类型，1管理员 2普通用户")
    private Integer accountType;

    @ApiModelProperty(value = "岗位id")
    private Integer positionId;

    @ApiModelProperty(value = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date createTime;

    @ApiModelProperty(value = "修改时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date updateTime;

    @ApiModelProperty(value = "手机号码")
    private String phone;

    @ApiModelProperty(value = "删除标识：0未删除 1已删除")
    private Integer deleted;

    @ApiModelProperty(value = "角色id集合")
    @TableField(exist = false)
    private Integer roleId;

    @ApiModelProperty(value = "部门id")
    @TableField(exist = false)
    private Integer departmentId;


    @NotNull(groups = Update.class,message = "主键不能为空")
    public static Admin convert(AdminVO vo) {
        Admin entity = new Admin();
        BeanUtils.copyProperties(vo,entity);
        return entity;
    }
    public static List<Admin> convertList(List<AdminVO> list) {
        List<Admin> resultList = new ArrayList<>();
        for (AdminVO vo : list) {
            resultList.add(convert(vo));
        }
        return resultList;
    }
}
